<template>
  <div class="menu">
    <el-table  class="message-menue" :data="messageList" @row-click="goToDetail">
      <el-table-column prop="content" label="问题" min-width="20px" width="auto"></el-table-column>
      <el-table-column prop="when" label="时间(↓)" min-width="20px" width="auto"></el-table-column>
      <el-table-column prop="ipAddress" label="IP" min-width="10px" width="auto"></el-table-column>
      <el-table-column  prop="response" label="回复" min-width="20px" width="auto" ></el-table-column>
      <el-table-column prop="good" label="是否收录为最佳问答" min-width="10px" width="auto">
        <template  slot-scope="scope">
          <span style="font-size: 14px" v-if="scope.row.good === 0">否</span>
          <span style="font-size: 14px;font-weight: bold;color: #54bf93" v-else>是</span>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <el-pagination class="page"
                   background
                   layout="prev, pager, next"
                   :total="100"
                   @current-change="handlePageChange">
    </el-pagination>
  </div>
</template>

<script>
import {Loading} from "element-ui";

export default {
  name: "PersonSpace",
  data(){
    return{
      messageList: [],
      currentPage: 1,  // 当前页码
      pageSize: 10,  // 每页显示的条数
      totalItems: 100,  // 总条数
      uid:''
    }
  },
  created() {
    let loading = Loading.service({fullscreen: true});
    let uid = this.$route.params.uid
    this.uid = uid
    this.getMessageList(this.currentPage, this.pageSize,uid)
    // location.reload()
    loading.close()
  },
  methods:{
    handlePageChange(currentPage) {
      this.currentPage = currentPage; // 更新当前页码
      this.getMessageList(currentPage, this.pageSize,this.uid); // 加载对应页码的对话数据
    },
    getMessageList(current, limit,uid) {
      this.$store.dispatch('getMessageByUid', {current, limit,uid}).then((res) => {
        console.log(res)
        this.messageList = res.messageList.records;
        this.totalItems = res.total
      })
    },
    goToDetail(row) {
      console.log(row)
      // 获取点击的行数据，根据需要获取相应的字段值
      const messageId = row.mid; // 假设行数据中有一个名为 id 的字段
      // 导航到详情页，将参数作为路由参数传递
      this.$router.push(`/question?mid=${messageId}`);
    },
  }
}
</script>

<style scoped>

</style>
